<template>
    <div>
        <better-scroll ref="scroll" class="scroll-t">
            <div class="mine-head ptb10 flex-row plr15">
                <div class="head-portrait" @click="$router.push({name:'personal-center'})"></div>
                <div class="head-userinfo flex-column">
                    <span class="head-name">{{userInfo.real_name?userInfo.real_name:'设置用户名'}}</span>
                    <span class="head-type">{{userInfo.level_name}}</span>
                    <div class="head-operation">
                        <span
                            class="head-update-psd"
                            @click.stop="$router.push({name:'update-password'})"
                        >修改密码</span>
                        <span class="head-layout" @click="layout">退出</span>
                    </div>
                </div>
            </div>
            <ul class="mine-integral flex-row plr15">
                <li
                    class="integral-item flex-column"
                    v-for="item in pointList"
                    @click="pointDetail(item)"
                >
                    <span
                        class="integral-point theme-color"
                        v-if="item.name!=='充值'"
                    >{{computePrice(item.point)}}</span>
                    <span class="integral-point theme-color" v-if="item.name=='充值'">&nbsp;</span>
                    <span class="integral-name">{{item.name}}</span>
                </li>
            </ul>
            <div class="mine-order plr15">
                <h3 class="order-title">我的订单</h3>
                <ul class="flex-row">
                    <li
                        class="order-item flex-column ptb10"
                        v-for="(item,index) in orderTab"
                        @click="orderList(index)"
                    >
                        <van-icon class="order-icon" :name="item.icon"></van-icon>
                        <span class="order-type-name">{{item.name}}</span>
                    </li>
                </ul>
            </div>
            <div class="mine-often-use plr15">
                <h3 class="order-title">我的常用</h3>
                <ul class="flex-row use-box ptb15">
                    <li
                        class="use-item flex-column"
                        v-for="item in useTab"
                        @click="routeName=item.name,$router.push({name:item.route,query:{name:item.name}})"
                    >
                        <van-icon class="use-icon order-icon" :name="item.icon"></van-icon>
                        <span class="use-name">{{item.name}}</span>
                    </li>
                </ul>
            </div>
        </better-scroll>
        <van-popup v-model="show" position="center" class="popup-box plr15">
            <h3 class="flex-column popup-title">充值</h3>
            <ul class="ptb15">
                <li class="popup-item" v-html="recharge"></li>
            </ul>
            <textarea name="" id="" cols="30" rows="3" v-model="message" class="textarea-message"></textarea>
            <span @click="submit" class="textarea-btn">确定</span>
        </van-popup>
    </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
    name: "Mine",
    data() {
        return {
            orderTab: [
                { name: "全部订单", icon: "orders-o" },
                { name: "待发货", icon: "send-gift-o" },
                { name: "待收货", icon: "logistics" },
                { name: "待评价", icon: "comment-o" }
            ],
            pointList: [],
            useTab: [
                { name: "购物积分", icon: "orders-o", route: "point-list" },
                { name: "增值积分", icon: "like-o", route: "point-list" },
                { name: "提现记录", icon: "bars", route: "point-list" },
                // {name: '股权投资', icon: 'chart-trending-o', route: 'point-list'},
                { name: "我的团队", icon: "cluster-o", route: "team" },
                { name: "我的二维码", icon: "qr", route: "qrcode" },
                { name: "收货地址", icon: "location-o", route: "address-list" },
                { name: "销售明细", icon: "shop-o", route: "point-list" },
                { name: "合作伙伴", icon: "friends-o", route: "point-list" }
            ],
            routeName: "",
            show: false,
            recharge: "",
            message: ""
        };
    },
    computed: {
        ...mapGetters(["userInfo"])
    },
    watch: {
        userInfo: function() {
            this.setInfo();
        }
    },
    created() {
        this.setInfo();
        this.rechargeInfo();
        console.log(this.userInfo);
    },
    methods: {
        rechargeInfo() {
            this.$store.dispatch(types.RECHARGE_INFO).then(res => {
                if (res.code == 0) this.recharge = res.info;
            });
        },
        setInfo() {
            this.pointList = [
                { name: "充值", point: this.userInfo.shop_point },
                { name: "购物积分", point: this.userInfo.shop_point },
                { name: "增值积分", point: this.userInfo.bonus_point },
                { name: "赠送股权", point: this.userInfo.stock },
                { name: "总收益", point: this.userInfo.total_income }
            ];
        },
        layout() {
            this.$store.dispatch(types.USER_LAYOUT);
            this.$router.push({ name: "login" });
        },
        orderList(index) {
            this.$router.push({ name: "order-list" });
            if (index > 0) index = index + 1;
            this.$store.commit(types.SET_ORDER_STATUS, index);
        },
        pointDetail(item) {
            if (item.name == "充值") return (this.show = true);
            if (item.name !== "总收益" && item.name !== "赠送股权") {
                this.$router.push({
                    name: "point-list",
                    query: { name: item.name }
                });
            }
        },
        // bbb
        submit() {
            this.$store
                .dispatch(types.RECHARGE, { mark: this.message })
                .then(res => {
                    if (res.code !== 0) return this.fail(res.msg, 2000);
                    this.success("提交成功", 1000);
                    this.message = "";
                    this.show = false;
                });
        }
    }
};
</script>

<style scoped lang="scss">
.mine-head {
    height: 100px;
    justify-content: flex-start;
    background: linear-gradient(#f99847, #f85e38);
    .head-portrait {
        height: 70px;
        width: 70px;
        border-radius: 100%;
        margin-right: 10px;
        background: url("../../../public/img/mine_header.png");
        background-size: 100% 100%;
    }
    .head-userinfo {
        align-items: flex-start;
        color: #fff;
        font-size: 16px;
        .head-name {
            font-weight: bold;
        }
        .head-operation {
            font-size: 14px;
            .head-layout {
                padding-left: 10px;
            }
        }
    }
}

.mine-integral {
    background: #fff;
    height: 60px;
    border-bottom: 1px solid #efefef;
    font-size: 14px;
}

.order-title {
    padding-top: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #efefef;
}

.order-icon {
    font-size: 25px;
    margin-bottom: 5px;
    color: $theme-color;
}

.mine-order {
    margin-top: 10px;
    background: #fff;
}

.mine-often-use {
    background: #fff;
    margin-top: 10px;
    .use-box {
        flex-wrap: wrap;
        justify-content: flex-start;
        .use-item {
            width: 33%;
            height: 60px;
            justify-content: center;
            margin-bottom: 20px;
        }
    }
}

.scroll-t {
    top: 0;
    bottom: 50px;
}
.popup-box {
    width: 80%;
    height: 50%;
    font-size: 14px;
    .popup-title {
        font-size: 16px;
        height: 40px;
        justify-content: center;
        border-bottom: 1px solid #efefef;
    }
    .popup-item {
        justify-content: center;
    }
}
.textarea-message {
    width: 100%;
    padding: 5px;
    border: 1px solid #eae3e3;
}
.textarea-btn {
    float: right;
    padding: 4px 10px;
    background: #f03726;
    border-radius: 1px;
    color: #fff;
    font-weight: 500;
}
</style>
